package com.szcinda.rpa.controller;

import com.szcinda.rpa.Result;
import com.szcinda.rpa.service.LoginDto;
import com.szcinda.rpa.service.UserService;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
@RequestMapping("/home")
public class HomeController {

    private final UserService userService;

    public HomeController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/")
    public String hello() {
        return LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    }

    @PostMapping("/authenticate")
    public Result<LoginDto> authenticate(@RequestParam("account") String account, @RequestParam("password") String password) {
        LoginDto loginDto = new LoginDto();
        loginDto.setAccount(account);
        loginDto.setPassword(password);
        userService.login(loginDto);
        return Result.success(loginDto);
    }
}
